home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Source Code / Zoners Half-Life Tools / hlcsg / wadpath.cpp < prev    next >
C/C++ Source or Header  |  2002-11-10  |  4KB  |  132 lines

  1. // AJM: added this file in
  2.  
  3. #include "csg.h"
  4.  
  5. wadpath_t*  g_pWadPaths[MAX_WADPATHS];
  6. int         g_iNumWadPaths = 0;    
  7.  
  8.  
  9. // =====================================================================================
  10. //  PushWadPath
  11. //      adds a wadpath into the wadpaths list, without duplicates
  12. // =====================================================================================
  13. void        PushWadPath(const char* const path, bool inuse)
  14. {
  15.     int         i;
  16.     wadpath_t*  current;
  17.  
  18.     if (!strlen(path))
  19.         return; // no path
  20.  
  21.     // check for pre-existing path
  22.     for (i = 0; i < g_iNumWadPaths; i++)
  23.     {
  24.         current = g_pWadPaths[i];
  25.  
  26.         if (!strcmp(current->path, path))
  27.             return; 
  28.     }
  29.  
  30.     current = (wadpath_t*)malloc(sizeof(wadpath_t));
  31.  
  32.     safe_strncpy(current->path, path, _MAX_PATH);
  33.     current->usedbymap = inuse;
  34.     current->usedtextures = 0;  // should be updated later in autowad procedures
  35.  
  36.     g_pWadPaths[g_iNumWadPaths++] = current;
  37.  
  38. #ifdef _DEBUG
  39.     Log("[dbg] PushWadPath: %i[%s]\n", g_iNumWadPaths, path);
  40. #endif
  41. }
  42.  
  43. // =====================================================================================
  44. //  IsUsedWadPath
  45. // =====================================================================================
  46. bool        IsUsedWadPath(const char* const path)
  47. {
  48.     int         i;
  49.     wadpath_t*  current;
  50.  
  51.     for (i = 0; i < g_iNumWadPaths; i++)
  52.     {
  53.         current = g_pWadPaths[i];
  54.         if (!strcmp(current->path, path))
  55.         {
  56.             if (current->usedbymap)
  57.                 return true;
  58.  
  59.             return false;
  60.         }
  61.     }   
  62.  
  63.     return false;
  64. }
  65.  
  66. // =====================================================================================
  67. //  IsListedWadPath
  68. // =====================================================================================
  69. bool        IsListedWadPath(const char* const path)
  70. {
  71.     int         i;
  72.     wadpath_t*  current;
  73.  
  74.     for (i = 0; i < g_iNumWadPaths; i++)
  75.     {
  76.         current = g_pWadPaths[i];
  77.         if (!strcmp(current->path, path))
  78.             return true;
  79.     }
  80.  
  81.     return false;
  82. }
  83.  
  84. // =====================================================================================
  85. //  FreeWadPaths
  86. // =====================================================================================
  87. void        FreeWadPaths()
  88. {
  89.     int         i;
  90.     wadpath_t*  current;
  91.  
  92.     for (i = 0; i < g_iNumWadPaths; i++)
  93.     {
  94.         current = g_pWadPaths[i];
  95.         free(current);
  96.     }
  97. }
  98.  
  99. // =====================================================================================
  100. //  GetUsedWads
  101. //      parse the "wad" keyvalue into wadpath_t structs
  102. // =====================================================================================
  103. void        GetUsedWads()
  104. {
  105.     const char* pszWadPaths;
  106.     char        szTmp[_MAX_PATH];
  107.     int         i, j;
  108.  
  109.     pszWadPaths = ValueForKey(&g_entities[0], "wad");
  110.  
  111.     for(i = 0; i < MAX_WADPATHS; i++)
  112.     {
  113.         memset(szTmp, 0, sizeof(szTmp));    // are you happy zipster?
  114.         for (j = 0; j < _MAX_PATH; j++, pszWadPaths++)
  115.         {
  116.             if (pszWadPaths[0] == ';')
  117.             {
  118.                 pszWadPaths++;
  119.                 PushWadPath(szTmp, true);
  120.                 break;
  121.             }
  122.  
  123.             if (pszWadPaths[0] == 0)
  124.             {
  125.                 PushWadPath(szTmp, true); // fix by AmericanRPG for last wadpath ignorance bug
  126.                 return;
  127.             }
  128.  
  129.             szTmp[j] = pszWadPaths[0];
  130.         }
  131.     }
  132. }